<?php 
/*
 * 彩页印刷网后台菜单管理
 * @auth 465578780@qq.com
 * 
 */
class OrderDataAction extends ContentAction{
	function index(){
		$dao = M("OrderData");
		if($_REQUEST['cat_id'] > 0){
			$map['cat_id'] = $_REQUEST['cat_id'];
		}
		if($_GET['select_type'] == 'order_id'){
		$map['order_id'] = array("like","%".trim($_REQUEST['keyword'])."%");
		}
		
		if($_GET['select_type'] == 'user_id'){
		$map['user_id'] = array("like","%".trim($_REQUEST['keyword'])."%");
		}
		$this->select_type = $_GET['select_type'];
		//取得满足条件的记录总数
		$count = $dao->where ( $map )->count (); //echo $dao->getLastSql();
		if ($count > 0) {
			import ( "@.ORG.Page" );
			//创建分页对象
			$listRows = 15;
			if (! empty ( $_REQUEST ['listRows'] )) {
				$listRows = $_REQUEST ['listRows'];
			}
			$page = new Page ( $count, $listRows );
			//分页查询数据
			$voList = $dao->where($map)->order("id DESC")->limit($page->firstRow . ',' . $page->listRows)->select ( );
			//分页显示
			$page = $page->show ();	
			//模板赋值显示
			$this->assign ( 'list', $voList );
			$this->assign ( 'page', $page );
		}
		$this->cat_id = $_REQUEST['cat_id'];
		$this->listRows = $_REQUEST['listRows'];
		
		$this->display();
	}
	function add(){
		$this->display('edit');
	}
	function edit(){
		$this->vo = M("OrderData")->find($_GET['id']);
		$this->display();
	}
	function update(){
		$data = $_POST;
		$data['update_time'] = time();
		$dao = M("OrderData");
		if($data['id']){
			$dao->create();
			$r = $dao->save();
			if($r){
				$this->success("提交成功",$_POST['forward']);
			}else{
				$this->success("提交失败");
			}
		}else{
			$this->success("缺少必要参数");
		}
	
	}
	function outExcel(){		
		$this->display();
	}
	public function outExc(){
		if($_GET['keyword'] ==false){
			$this->success("缺少必要参数");
			exit();
		}
		$where['order_id'] = array("like","%".trim($_GET['keyword'])."%");
		$order = "order_id desc";
		$res = M("OrderData")->where($where)->order($order)->select();	
		//$title = $_GET['title'];
		$title = $_GET['keyword']."记录";
		
		$type_arr = array(1=>"彩页",2=>"画册",3=>"手袋",4=>"名片");
		$status_arr = array(1=>"新订单",2=>"处理中",3=>"已完成");
		
		header("Content-type:application/vnd.ms-excel");
		header("Content-Disposition:attachment;filename=".$title.".xls");
		echo "订单号\t";
		echo "文件上传\t";
		echo "文件名\t";
		echo "订单状态\t";
		echo "项目\t";
		echo "规格\t";
		echo "材质\t";
		echo "工艺\t";
		echo "数量\t";
		echo "金额\t";
		echo "发货方式\t";
		echo "收件人\t";
		echo "收件人电话\t";
		echo "收件人地址\t";
		echo "留言\t";
		echo "\n";
		foreach($res as $i=>$v){			 
			echo $v['order_id']."\t";
			echo $v['file_up_type']."\t";
			echo $v['file_name']."\t";
			echo $status_arr[$v['status']]."\t";
			echo $type_arr[$v['cat_id']]."\t";
			echo $v['size']."\t";
			echo $v['material']."\t";
			echo $v['technics']."\t";
			echo $v['number']."\t";
			echo $v['price']."\t";
			echo $v['shipping']."\t";
			echo $v['to_user']."\t";
			echo $v['to_phone']."\t";
			echo $v['to_address']."\t";
			echo $v['comment']."\t";
			echo "\n";
		}
	
	}
}

?>